package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String phone) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile", phone);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user); //添加完成后，新数据对应的字段都会自动映射到user对象的属性中
        return user.getId();
    }

    @Override
    public void updatePhone(User user) {
        userMapper.updateById(user);
    }

    /**
     * 更新环信用户信息
     *
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public User findByhuanxinId(String huanxinId) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("hx_user", huanxinId);
        return userMapper.selectOne(wrapper);
    }
}
